package com.ccc.demoboot.service;

import com.ccc.demoboot.dao.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccc.demoboot.pojo.Menu;
import com.ccc.demoboot.dao.MenuMapper;
import com.ccc.demoboot.service.MenuService;

/**
 * @Author wz
 * @Date 2024/5/16 9:57
 * @PackageName:com.ccc.demoboot.service
 * @ClassName: MenuServiceImpl
*/
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService{
    @Autowired
    RoleMapper roleMapper;

    @Override
    public List<Menu> selectMenuByUser(Integer id) {
        //1、根据用户id查询(包括部门id、岗位id)拥有的角色id集合
        List<Integer> roleIdsList = this.roleMapper.selectRoleIdsByUserid(id);//返回角色id集合
        //2、根据角色id集合查询所拥有的菜单集合对象
        String roleids = roleIdsList.toString().replaceAll("\\[", "").replaceAll("\\]", "");

        if (roleIdsList==null || roleIdsList.size()<1) {
            roleids="0";
        }

        List<Menu> menuList = this.getBaseMapper().selectMenusByRoleids(roleids);
        return menuList;
    }




}
